package com.atguigu.gmall.product.api;

import com.atguigu.gmall.model.product.BaseCategoryView;
import com.atguigu.gmall.model.product.SkuInfo;
import com.atguigu.gmall.model.product.SpuSaleAttr;
import com.atguigu.gmall.product.service.ManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * 商品、库存、对外暴露
 */
@RestController
@RequestMapping("/api/product")
@EnableSwagger2
public class ProductApiController {

    @Autowired
    private ManageService manageService;

    //1、根据skuId查询skuInfo信息
    @GetMapping("/inner/getSkuInfo/{skuId}")
    public SkuInfo getSkuInfo(@PathVariable(name = "skuId")Long skuId){
        return manageService.getSkuInfo(skuId);
    }

    //2、根据三级分类ID查询一二三级分类
    @GetMapping("/inner/getCategoryView/{category3Id}")
    public BaseCategoryView getCategoryView(@PathVariable(name = "category3Id")Long category3Id){
        return manageService.getCategoryView(category3Id);
    }

    //3、根据skuId查询库存表中的价格
    @GetMapping("/inner/getSkuPrice/{skuId}")
    public BigDecimal getSkuPrice(@PathVariable(name = "skuId")Long skuId){
        return manageService.getSkuPrice(skuId);
    }

    //4、根据spuId查询销售属性以及属性值 集合；根据skuId查询当前选中项
    @GetMapping("/inner/getSpuSaleAttrListCheckBySku/{skuId}/{spuId}")
    public List<SpuSaleAttr> getSpuSaleAttrListCheckBySku(
            @PathVariable(name = "skuId")Long skuId,
            @PathVariable(name = "spuId")Long spuId){
        return manageService.getSpuSaleAttrListCheckBySku(skuId,spuId);
    }

    //5、根据spuId查询销售组合与SkuId之间的对应
    @GetMapping("/inner/getSkuValueIdsMap/{spuId}")
    public Map getSkuValueIdsMap(@PathVariable(name = "spuId") Long spuId){
        return manageService.getSkuValueIdsMap(spuId);
    }

}
